<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/jsp/common/inc.jsp"%>
<title>费率配置</title>
<script type="text/javascript">
	var datagrid;
	$(function() {
		$("#datagrid").datagrid({
			url : "${pageContext.request.contextPath}/rateController/datagrid",
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			fitColumns : true,
			idField : "id",
			pagesize : 10,
			pageList : [10,20,30],
			toolbar : "#toolbar",
			columns : [[{
				width : 100,
				title : "欠款类型",
				field : "id"
			},{
				width : 100,
				title : "欠款方式名称",
				field : "name"
			},{
				width : 100,
				title : "费率",
				field : "rate"
			},{
				width : "100",
				title : "结算周期(天)",
				field : "jszq"
			},{
				width : 100,
				title : "备注",
				field : "remark"
			},{
				width : 100,
				title : "操作",
				field : "action",
				formatter : function(value, rowData, rowIndex){
					return "<button onclick='updateFun(" + rowIndex + ")'>修改</buttion>";
				}
			}]]
		});
	});
	
	function searchFun(){
		$("#datagrid").datagrid("load",sy.serializeObject($("#_form")));
	}
	
	function clearFun(){
		$("#_form").find("input").val("");
		$("#datagrid").datagrid("load",{});
	}
	// 修改
	function updateFun(rowIndex){
		// 获得选中的行
		var row = $("#datagrid").datagrid("getRows")[rowIndex];
		$("#_window").window("open");
		$("#form2").form("load",row);
	}
	// 保存信息
	function update(){
		$("#form2").form("submit",{
			url : "${pageContext.request.contextPath}/rateController/update",
			onSubmit : function(){
				var isValid = $("#form2").form('validate');
				return isValid;
			},
			success : function(data){
				var obj = $.parseJSON(data);
				if(obj.success){
					$.messager.alert('提示','保存成功','info');
				}else{
					$.messager.alert('提示',obj.msg,'error');
				}
				$.messager.progress('close'); // 如果提交成功则隐藏进度条
				$("#_window").window('close');
				$("#datagrid").datagrid("reload");//重新加载datagrid
			}
		});
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	
	<div id="toolbar" style="display: none;">
		<form id="_form">
			<table>
				<tr>
					<td>欠款类型</td>
					<td><input id="id" name="id" /></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton"
						onclick="searchFun()">查询</a></td>
					<td><a href="javascript:void(0)" class="easyui-linkbutton"
						onclick="clearFun()">清空</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div data-options="region:'center',fit:true,border:false">
		<table id="datagrid" data-options="fit:true,border:false"></table>
	</div>
	
	<!-- 弹出窗口 -->
	<div id="_window" class="easyui-window"
		data-options="modal:true,closed:true,collapsible:false,minimizable:false"
		style="width: 600px; height: 400px; padding: 10px;">
		    
		  <div data-options="region:'center' ">
              <form id="form2" method="post" style="padding-top: 15px">
					<input  type="hidden" name="id" data-options="required:true" />
					<table align="center" style="height: 150px">
					<tr>
							<td>欠款方式名称</td>
							<td><input  class="easyui-textbox" type="text" name="name" data-options="required:true" readonly="readonly"/>
							</td>
					</tr>
					   <tr>
							<td>费率:</td>
							<td><input class="easyui-textbox" type="text" name="rate" data-options="required:true,validType:'length[2,10]'"></input></td>
						</tr>
						
						<tr>
							<td>结算周期(天):</td>
							<td><input class="easyui-numberbox textbox" type="text" name="jszq" data-options="required:true" ></input></td>
						
						</tr>
						<tr>
							<td>备注:</td>
							<td><input class="easyui-textbox" type="text" name="remark" data-options="validType:'length[0,20]'"></input></td>
						</tr>	    		
					</table>
			  </form>
		  </div>
		    
		  <div data-options="region:'south',border:false" style="height:50px">
             	 <div style="text-align:center;padding:5px">
						    	<a href="javascript:void(0)"data-options="iconCls:'icon-ok'" class="easyui-linkbutton" onclick="update()">提交</a>			    
						     	<a href="javascript:void(0)"data-options="iconCls:'icon-cancel'"  class="easyui-linkbutton" onclick="$('#_window').window('close')">关闭</a>
				 </div>
          </div> 
	</div>

</body>
</html>
